var systemManageCollection = require('../../../SystemManage/server/controllers/App.server.controller');

//网关调用更新全部App
exports.updateApps = function(req, res) {
	var apps = req.body.Apps;
	systemManageCollection.updateApps(apps, function(err, data){
		if(err){
			res.json({
                Error: err
            });
		}
		else{
			res.json({
                Data: data
            });
		}
	});
};

//根据请求用户，获取所有App信息
exports.getApps = function(req, res) {
	// 0：平板；1：PDA
	var type = req.body.Type;
	if(req.user == null || req.user == undefined){
		res.json({
            Error: {
            	level: 5,
            	title: '获取App信息失败',
            	message: '用户未登录，不能获取App信息'
            }
        });
	}
	else{
		systemManageCollection.getApps(req.user._id, type, function(err, data){
			if(err){
				res.json({
	                Error: err
	            });
			}
			else{
				res.json({
	                Data: data
	            });
			}
		});
	}
};

exports.getAppByAppId = function(req, res) {
	var appId = req.body.AppId;
	systemManageCollection.getAppByAppId(appId, function(err, data){
		if(err){
			res.json({
                Error: err
            });
		}
		else{
			res.json({
                Data: data
            });
		}
	});
};
